const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
})

const path = require('path')
module.exports = {
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      patterns: [
        // 全局变量路径
        path.resolve(__dirname, './src/assets/css/global.less'),
      ],
    },
  },
  devServer: {
    open: true,
    host: '192.168.136.223',
    port: '8089',
    proxy: {
      [process.env.VUE_APP_BASE_API]: {
        target: process.env.VUE_APP_BASE_API,
        ws: true,
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: '',
        },
      },
      // 灵活代理；请求前缀为/api时，走下面的代理
      '/api': {
        // 代理服务器把请求转发给url(真正的后台服务器)
        target: 'https://news.sina.com.cn',
        // 用于支持websocket
        ws: true,
        secure: false,
        // 用于控制请求头中的host值
        changeOrigin: true,
        // 真正的服务器没有/api，所以要重写路径置空，否则找不到相应的路径
        pathRewrite: {
          // 匹配以api开头的路径置空
          '^/api': 'https://news.sina.com.cn',
        },
      },
      '/enews': {
        target: 'https://shankapi.ifeng.com',
        ws: true,
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '^/enews': 'https://shankapi.ifeng.com',
        },
      },
    },
  },
}
